﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using LTP.Common;
using LTP.Accounts.Bus;
namespace TCS.Web.Admin.MemberManage
{
    public partial class add : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!this.IsPostBack)
            {
                BindSuppData();
                SetRights();
            }
        }
        private void BindSuppData()
        {
            TCS.BLL.Gsp_Administrative bll = new TCS.BLL.Gsp_Administrative();
            this.dropArea.DataSource = bll.GetList("addId!=1");
            this.dropArea.DataTextField = "addName";
            this.dropArea.DataValueField = "addId";
            this.dropArea.DataBind();

            this.dropArea.Items.Insert(0, new ListItem("--请选择--", "-1"));
        }
        private void SetRights()
        {
            //AccountsPrincipal user = new AccountsPrincipal(Context.User.Identity.Name);
            string dpid = new LTP.Accounts.Bus.User().GetUserdepartmentID(Context.User.Identity.Name);
            if (dpid!= "1")
            {
                dropArea.SelectedIndex = -1;
                dropArea.Items.FindByValue(dpid).Selected=true;
                dropArea.Enabled = false;
            }
        }
        protected void btnAdd_Click(object sender, EventArgs e)
        {
            string strErr = "";
          
            if (this.txtCodeName.Text == "")
            {
                strErr += "登录名不能为空！\\n";
            }
            if (this.txtPassword.Text == "")
            {
                strErr += "密码不能为空！\\n";
            }
            if (this.txtEnName.Text == "")
            {
                strErr += "企业名称不能为空！\\n";
            }
            
            if (this.dropArea.SelectedValue=="-1")
            {
                strErr += "请选择行政区域！\\n";
            }
          
            if (strErr != "")
            {
                MessageBox.Show(this, strErr);
                return;
            }
            
            string CodeName = this.txtCodeName.Text;
            string Password = this.txtPassword.Text;
            string EnName = this.txtEnName.Text;
            int AddID = int.Parse(this.dropArea.SelectedValue);
            
            string CreateTime = this.txtCreateTime.Text;
            string BisAddr = this.txtBisAddr.Text;
            string BisPost = this.txtBisPost.Text;
            string WarehouseAddr = this.txtWarehouseAddr.Text;
            string WarehousePost = this.txtWarehousePost.Text;
            string LegalName = this.txtLegalName.Text;
            string LegalTel = this.txtLegalTel.Text;
            string LegalAddr = this.txtLegalAddr.Text;
            string LegalPost = this.txtLegalPost.Text;
            string MgrName = this.txtMgrName.Text;
            string MgrTel = this.txtMgrTel.Text;
            string MgrEmail = this.txtMgrEmail.Text;
            string ContactName = this.txtContactName.Text;
            string ContactTel = this.txtContactTel.Text;
            string ContactEmail = this.txtContactEmail.Text;
            int IsDelete = 0;
            string AddTime = System.DateTime.Now.ToString();
            string LastLoginTime = "";
            string AboutUs = this.txtAboutUs.Text;
            string OrgStructure = this.txtOrgStructure.Text;
            string ManageSystem = this.txtManageSystem.Text;
            string Qualification = this.txtQualification.Text;

            TCS.Model.MemberInfo model = new TCS.Model.MemberInfo();
            //model.CodeName = CodeName;
            //model.Password = Password;
            //model.EnName = EnName;
            //model.CreateTime = CreateTime;
            //model.Addid = AddID;
            //model.BisAddr = BisAddr;
            //model.BisPost = BisPost;
            //model.WarehouseAddr = WarehouseAddr;
            //model.WarehousePost = WarehousePost;
            //model.LegalName = LegalName;
            //model.LegalTel = LegalTel;
            //model.LegalAddr = LegalAddr;
            //model.LegalPost = LegalPost;
            //model.MgrName = MgrName;
            //model.MgrTel = MgrTel;
            //model.MgrEmail = MgrEmail;
            //model.TrueName = ContactName;
            //model.ContactTel = ContactTel;
            //model.Email = ContactEmail;
            //model.Isdelete = IsDelete;
            //model.AddTime = AddTime;
            //model.LastLoginTime = LastLoginTime;
            //model.Image = AboutUs;
            //model.QQ = OrgStructure;

            TCS.BLL.MemberInfo bll = new TCS.BLL.MemberInfo();
            bll.Add(model);
            if (chkAddContinue.Checked)
            {
                Response.Redirect("Add.aspx");
            }
            else
            {
                Response.Redirect("index.aspx");
            }
        }

        protected void btnCancel_Click(object sender, EventArgs e)
        {
            Response.Redirect("Add.aspx");
        }

    }
}
